package com.study.order.amqp;

import com.study.order.entity.Order;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.UUID;

public class RabbitMqSendMessage {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMessage() {
        /**
         * 发送消息  交换机名称,路由键,发送内容
         */
        rabbitTemplate.convertAndSend("order-exchange", "order-key", "hello", new CorrelationData(UUID.randomUUID().toString()));
    }

    public void sendMessageObject(Order order) {
        /**
         * 发送消息  交换机名称,路由键,发送内容
         * 发送的内容是个对象,我们使用序列化机制，将对象写出去,对象必须实现 Serializable接口
         */
        rabbitTemplate.convertAndSend("order-exchange", "order-key", order, new CorrelationData(UUID.randomUUID().toString()));
    }
}
